<template>
	<view>
		<text>正在获取用户信息，请稍候...</text>
		<!-- <view>
			{{code}}
		</view>
		<view>{{openid}}</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				code: '',
				winUrl: '',
				openid: {}
			}
		},
		onLoad(query) {
			let url = location.href //获取打开的公众号的路径	
			// 提取 code 值
			let urlParams = new URLSearchParams(url.split('?')[1]);
			this.code = urlParams.get('code');
			this.getOpenId();
			console.log(this.code);
		},
		methods:{
			getOpenId(){
				let opt = {
					url:'wx/getUserAccessToken/'+ this.code,
					method:'GET'
				};
				this.$http.httpRequest(opt).then(res => {
					this.openid = res.data.data
					uni.setStorageSync('WXUserToken',res.data.data)
					setTimeout(()=>{
						uni.switchTab({
							url: '/pages/control-tower/control-tower'
						});
					},800)
				})
			}
		}
	};
</script>